package com.juc.learn.reviewsynchronized_1;

/**
 * ClassName:Test
 * Package:com.juc.learn.reviewsynchronized_1
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/26 - 10:36
 * @Version:v1.0
 */
public class Test {
    public static void main(String[] args) {
        SaleTicket saleTicket = new SaleTicket();
        //创建三个线程
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 40; i++) {
                    saleTicket.sale();
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        },"线程1").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 40; i++) {
                    saleTicket.sale();
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        },"线程2").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 40; i++) {
                    saleTicket.sale();
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        },"线程3").start();
    }
}
